<?php
declare (strict_types = 1);

namespace app\api\validate;

use app\common\model\Users;
use think\Validate;

class User extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        "phone|手机号"=>"require|mobile",
        "yzm|验证码"=>"require|length:6",
//        "pass|密码"=>"require|confirm:again_pass",
//        "invite_code|邀请码"=>"checkInvite"
    ];

    protected function checkInvite($val)
    {
        $parent = Users::where('invite_code', $val)
            ->find();
        if(empty($parent)){
            return "邀请码不存在";
        }
        return true;
    }
    

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [];
}
